/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.controller;

import cn.webrx.pojo.Result;
import com.alibaba.fastjson.JSON;
import org.springframework.cglib.core.Local;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: smvc2022 - Index
 * <p>Powered by webrx On 2022-03-19 15:57:38
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */

@RestController
public class Index {
    @GetMapping("m1")
    public String m1() {
        Integer code = 200;
        String msg = "信息处理中";
        return String.format("{\"code\":%d,\"msg\":\"%s\"}", code, msg);
    }

    @GetMapping("m2")
    public String m2() {
        //fastjson
        Map<String, Object> map = new HashMap<String, Object>();
        Integer code = 88;
        String msg = "信息处理中";
        map.put("code", code);
        map.put("msg", msg);
        //return String.format("{\"code\":%d,\"msg\":\"%s\"}",code,msg);
        return JSON.toJSONString(map);
    }


    @GetMapping("/")
    public Map<String, Object> index() {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("code", 200);
        map.put("msg", "首页信息");
        return map;
    }

    @GetMapping("/ok")
    public Result show() {
        Result result = new Result();
        result.setCode(2222);
        result.setMsg("信息成33功");
        return result;
    }

    @GetMapping("/d1")
    public Date d1() {
        return new Date();
    }

    @GetMapping("/d2")
    public LocalDate d2() {
        return LocalDate.now();
    }

    @GetMapping("/d3")
    public LocalDateTime d3() {
        return LocalDateTime.now();
    }

    @GetMapping("/d4")
    public LocalTime d4() {
        return LocalTime.now();
    }

    @GetMapping("/dd")
    public Map<String, Object> dd() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", "100");
        map.put("name", "张三丰");
        map.put("langs", new String[]{"java", "html", "mysql", "python"});
        map.put("d1", new Date());
        map.put("d2", LocalDate.now());
        map.put("d3", LocalTime.now());
        map.put("d4", LocalDateTime.now());
        return map;
    }
}
